package companyTest.tianrongxin;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        boolean []tag=new boolean[n];
        tag[0]=true;
        List<Integer>[]lists=new List[n];
        for (int i = 0; i <n ; i++) {
            String s=in.nextLine();
            System.out.println(s);
            if (!s.equals(" ")&&s.length()!=0){
                int count=Integer.parseInt(s);
                lists[i]=new ArrayList<>();
                for (int j = 0; j < count; j++) {
                    lists[i].add(in.nextInt());
                }
            }else break;
        }
        Queue<Integer>queue=new ArrayDeque<>();
        queue.offer(0);
        while (!queue.isEmpty()){
            int index=queue.poll();
            List<Integer> keys=lists[index];
            if (keys!=null){
                for (Integer key : keys) {
                    if (!tag[key]){
                        queue.offer(key);
                        tag[key]=true;
                    }
                }
            }
        }
        boolean flag=true;
        for (int i = 0; i < n; i++) {
            if (!tag[i])flag=false;
        }
        System.out.println(flag);
    }
}
